﻿using System;
using System.Collections.Generic;
using Microsoft.SharePoint;
using SimpleFS.Core;

namespace SimpleFS.Storage.SharePoint
{
    public class Directory : IDirectory
    {
        protected string name;

        protected SPFolder folder;

        protected SPWeb web;

        public Directory(string name)
        {
            this.name = name;
            SPSite site = new SPSite(name);
            web = site.OpenWeb();

            this.folder = web.GetFolder(name);
        }

        protected Directory(SPFolder folder)
        {
            this.folder = folder;
        }

        #region IDirectory Members

        public IDirectory[] Directories
        {
            get
            {
                IDirectory[] directories = new Directory[this.folder.SubFolders.Count];
                for (int index = 0; index < directories.Length; index++)
                {
                    directories[index] = new Directory(this.folder.SubFolders[index]);
                }

                return directories;
            }
        }

        public IFile[] Files
        {
            get
            {
                IFile[] files = new File[this.folder.Files.Count];
                for (int index = 0; index < files.Length; index++)
                {
                    files[index] = new File(this.folder.Files[index]);
                }

                return files;
            }
        }

        public void Create()
        {
            throw new NotImplementedException();
        }

        public IDirectory GetDirectory(string directoryName)
        {
            throw new NotImplementedException();
        }

        public IFile GetFile(string fileName)
        {
            throw new NotImplementedException();
        }

        public IFile AddFile(string fileName)
        {
            throw new NotImplementedException();
        }

        public IDirectory AddDirectory(string directoryName)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IFileSystemObject Members

        public string Name
        {
            get { throw new NotImplementedException(); }
        }

        public DateTime LastModifiedTime
        {
            get { throw new NotImplementedException(); }
        }

        public Dictionary<string, string> Attributes
        {
            get { throw new NotImplementedException(); }
        }

        public IDirectory ParentDirectory
        {
            get { throw new NotImplementedException(); }
        }

        public int Size
        {
            get { throw new NotImplementedException(); }
        }

        public void Copy(IFileSystemObject target)
        {
            throw new NotImplementedException();
        }

        public void Move(IFileSystemObject target)
        {
            throw new NotImplementedException();
        }

        public void Delete()
        {
            throw new NotImplementedException();
        }

        public bool Exists()
        {
            throw new NotImplementedException();
        }

        public void Rename(string newName)
        {
            throw new NotImplementedException();
        }

        public void Close()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
